/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    InputNumber,
} from 'antd';
// import Addtable from './Addtable';
const FormItem = Form.Item;
const { Option } = Select
const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
        span: 6
    },
    wrapperCol: {
        span: 18
    }
};
class AddFrom extends PureComponent {
    state = {
        types: null,
        data: ['试机前检查', '试机准备', '电讯号检测', '调节比例电流', '主电路检测', '压力测试', '机械动作调试', '精度', '技术参数', '空运转试验', '信号检测', '动作检测', '参数检验', '外观检查']

    }
    // 判断选中显示隐藏
    selects = (value) => {
        console.log('当前类型选中', value);
        this.setState({
            types: this.state.types = value,
        })
    }
    render() {
        const {
            formData,
            one,
            form: { getFieldDecorator },
        } = this.props;
        console.log('判断新增休息', one, this.state.types);
        return (
            <Form >
                <Row>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验标准编码:'}>
                            {getFieldDecorator('checkItemCode', {
                                initialValue: one ? formData.checkItemCode : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '检验标准编码不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入检验标准编码' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验标准名称:'}>
                            {getFieldDecorator('checkItemName', {
                                initialValue: one ? formData.checkItemName : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '检验标准名称不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入检验标准名称' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'所属表单:'}>
                            {getFieldDecorator('formProperties', {
                                initialValue: one ? formData.formProperties : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '所属表单为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入所属表单' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'备注:'}>
                            {getFieldDecorator('remark', {
                                initialValue: one ? formData.remark : null,
                                rules: [
                                    {
                                        required: false,
                                        message: ''
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入备注' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'第一类机型:'}>
                            {getFieldDecorator('checkTypeFirst', {
                                initialValue: one ? formData.checkTypeFirst : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '第一类机型不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input placeholder='输入第一类机型' allowClear maxLength={20} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'第二类分类:'}>
                            {getFieldDecorator('checkTypeSecond', {
                                initialValue: one ? formData.checkTypeSecond : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '第二类分类不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入第二类分类' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'检验项目属性:'}>
                            {getFieldDecorator('checkItemProperty', {
                                initialValue: one ? formData.checkItemProperty : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '检验项目属性为空'
                                    }
                                ]
                            })(<Select allowClear={true} onChange={(value) => { this.selects(value) }}>
                                <Option value={1} key={1}>范围</Option>
                                <Option value={2} key={2}>文本</Option>
                                <Option value={3} key={3}>唯一值</Option>
                                <Option value={4} key={4}>复选</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    {
                        this.state.types === 1 || (one ? formData.checkItemProperty : null) === 1 ? <Col span={24}>
                            <FormItem {...formItemLayout} label={'是否包含最大值:'}>
                                {getFieldDecorator('containMax', {
                                    initialValue: one ? formData.containMax : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '是否包含最大值选择项不能为空'
                                        }
                                    ]
                                })(
                                    <Select allowClear={true}>
                                        <Option value={1}>包含</Option>
                                        <Option value={0}>不包含</Option>
                                    </Select>
                                )}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'是否包含最小值:'}>
                                {getFieldDecorator('containMin', {
                                    initialValue: one ? formData.containMin : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '是否包含最小值选择项不能为空'
                                        }
                                    ]
                                })(
                                    <Select allowClear={true}>
                                        <Option value={1}>包含</Option>
                                        <Option value={0}>不包含</Option>
                                    </Select>
                                )}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'最小值:'}>
                                {getFieldDecorator('checkStandardMin', {
                                    initialValue: one ? formData.checkStandardMin : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '检验标准不能为空'
                                        }
                                    ]
                                })(<InputNumber min={0} max={9999999999} />)}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'最大值:'}>
                                {getFieldDecorator('checkStandardMax', {
                                    initialValue: one ? formData.checkStandardMax : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '检验标准不能为空'
                                        }
                                    ]
                                })(<InputNumber min={0} max={9999999999} />)}
                            </FormItem>
                            <FormItem {...formItemLayout} label={'单位:'}>
                                {getFieldDecorator('unit', {
                                    initialValue: one ? formData.unit : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '单位不能为空'
                                        }
                                    ],
                                    getValueFromEvent: (event) => {
                                        return event.target.value.replace(/\s+/g, "")
                                    },
                                })(<Input placeholder='请输入单位' style={{ width: '150px' }} allowClear maxLength={20} />)}
                            </FormItem>
                        </Col> : ''
                    }
                    {this.state.types === 2 || (one ? formData.checkItemProperty : null) === 2 ? <Col span={24}>
                        <FormItem {...formItemLayout} label={'文本:'}>
                            {getFieldDecorator('checkStandardText', {
                                initialValue: one ? formData.checkStandardText : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '文本不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input placeholder='输入检验标准' allowClear maxLength={20} />
                            )}
                        </FormItem>
                    </Col> : ''}
                    {this.state.types === 3 || this.state.types === 4 || (one ? formData.checkItemProperty : null) === 3 || (one ? formData.checkItemProperty : null) === 4 ? <Col span={24}>
                        <FormItem {...formItemLayout} label={this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? '唯一值1' : '复选1'}>
                            {getFieldDecorator('checkStandardOption1', {
                                initialValue: one ? formData.checkStandardOption1 : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '请输入数据'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input allowClear placeholder='请填写数据' maxLength={20}></Input>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? '唯一值2' : '复选2'}>
                            {getFieldDecorator('checkStandardOption2', {
                                initialValue: one ? formData.checkStandardOption2 : null,
                                // valuePropName: 'checkStandardOption2',
                                rules: [
                                    {
                                        required: false,
                                        message: '请填写数据'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input allowClear placeholder='请填写数据' maxLength={20}></Input>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? '唯一值3' : '复选3'}>
                            {getFieldDecorator('checkStandardOption3', {
                                initialValue: one ? formData.checkStandardOption3 : null,
                                // valuePropName: 'checkStandardOption3',
                                rules: [
                                    {
                                        required: false,
                                        message: '请填写数据'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input allowClear placeholder='请填写数据' maxLength={20}></Input>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? '唯一值4' : '复选4'}>
                            {getFieldDecorator('checkStandardOption4', {
                                initialValue: one ? formData.checkStandardOption4 : null,
                                // valuePropName: 'checkStandardOption4',
                                rules: [
                                    {
                                        required: false,
                                        message: '请填写数据'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input allowClear placeholder='请填写数据' maxLength={20}></Input>
                            )}
                        </FormItem>
                        <FormItem {...formItemLayout} label={this.state.types === 3 || (one ? formData.checkItemProperty : null) === 3 ? '唯一值5' : '复选5'}>
                            {getFieldDecorator('checkStandardOption5', {
                                initialValue: one ? formData.checkStandardOption5 : null,
                                // valuePropName: 'checkStandardOption5',
                                rules: [
                                    {
                                        required: false,
                                        message: '请填写数据'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(
                                <Input allowClear placeholder='请填写数据' maxLength={20}></Input>
                            )}
                        </FormItem>
                    </Col> : ''}
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'排序层级:'}>
                            {getFieldDecorator('sort', {
                                initialValue: one ? formData.sort : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '请输入排序层级'
                                    }
                                ]
                            })(<InputNumber min={0} max={9999999999} />)}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        );
    }
}
export default Form.create()(AddFrom);
